home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / CHASSIS_ / MAIN.C < prev    next >
C/C++ Source or Header  |  1992-05-27  |  9KB  |  268 lines

  1. /************************************************************************************/
  2. /*                                                                                    */
  3. /*    Program Name:  Chassis                                                            */
  4. /*  Version:  4.2.1                                                                    */
  5. /*                                                                                    */
  6. /*    by:        Charles A. Hoffman                                                        */
  7. /*                                                                                    */
  8. /*            ASSIST Consulting            - or -            GTE Laboratories            */
  9. /*            P.O. Box 857                                Mail Stop 24                */
  10. /*            Norwood, MA  02062                            40 Sylvan Road                */
  11. /*                                                        Waltham, MA  02254            */
  12. /*            Phone: (617) 551-0185                                                    */
  13. /*                                                        Phone: (617) 466-2131        */
  14. /*                                                                                    */
  15. /************************************************************************************/
  16. /*                                                                                    */
  17. /*        This program contains material from a version of the sample program            */
  18. /*        "Chassis," and the application program "MacEden," which were originally        */
  19. /*        created and copyrighted by Charles A. Hoffman.                                */
  20. /*                                                                                    */
  21. /************************************************************************************/
  22. /*                                                                                    */
  23. /*    Compiled with Symantec Corp. THINK C 5.0.1                                        */
  24. /*                                                                                    */
  25. /************************************************************************************/
  26.  
  27. #include "MyHeaders.h"
  28.  
  29. /************************************************************************************/
  30. /*    MAIN                                                                            */
  31. /************************************************************************************/
  32. main()
  33. {
  34.     MainRetCode = 0;                                /* initialize return code        */
  35.     
  36.     myResRefNum = CurResFile();                        /* Get own resource file number    */
  37.  
  38.     versRecHandle = (struct versRec **) GetResource ('vers',1);    /* get vers resrce    */
  39.     HLock (versRecHandle);
  40.     j = (int) (**versRecHandle).versChar[6];
  41.     k = (int) (**versRecHandle).versChar[6+1+j];    /* k is length of long string    */
  42.     for (m = 0; m < k+2; m++)
  43.         versLongStr[m] = (**versRecHandle).versChar[6+j+1+m];
  44.     HUnlock (versRecHandle);
  45.     ReleaseResource (versRecHandle);
  46.     
  47.     WorkRetCode = InitMac();                        /* Start the managers            */
  48.     
  49.     WorkRetCode = ColorCheck();                        /* Set "useColor" global        */
  50.  
  51.     UseResFile (initResRefNum);            
  52.     prRecHdl = (THPrint) (NewHandle (sizeof (TPrint)));    /* get handle for print rec    */
  53.     PrintDefault (prRecHdl);                            /* initialize print rec        */
  54.     prPortPtr = (TPPrPort) (NewPtr (sizeof (TPrPort)));    /* get ptr to prnt port        */
  55.  
  56.     WorkRetCode = SetUpMenus();                        /* set up the menus                */
  57.  
  58. /**    WorkRetCode = ShowInfoDlog(128);                /* display the "About" dialog    */
  59.  
  60.     myDragRect = screenBits.bounds;                    /* Set the boundries...            */
  61.     InsetRect(&myDragRect,10,10);                    /* ...for dragging                */
  62.     
  63.     for (j=0; j<windMax; j++)                        /* Indicate all entries in        */
  64.         windTbl[j].windPtr = 0;                        /*   windTbl are not in use        */
  65.     SetPt (&nextTextPosit, 10,40);                    /* Set posit of first text wind    */
  66.     
  67.     workRegionH = NewRgn();                            /* get region for TE clikloop    */
  68.  
  69.     WorkRetCode = MainGetProc();                    /* put the main window up        */
  70.  
  71.     myQuitFlag = 0;                                    /* set flag for main event loop    */
  72.     
  73.     WorkRetCode = FinderFilesProc();            /* process any files from finder    */
  74.  
  75.     /**************************                                                     */
  76.     /*    Main Event Loop          *                                                        */
  77.     /**************************                                                     */
  78.     while (myQuitFlag == 0)                        /* loop till quit                    */
  79.         {
  80.  
  81.         GetMouse (&locMouse);                    /* where is the mouse?                */
  82.         gMouse = locMouse;                        /* convert to ..                    */
  83.         LocalToGlobal(&gMouse);                    /* .. global coordinates            */
  84.         mouseWindPart = FindWindow (gMouse, &mouseWindPtr);        /* get ptr & part    */
  85.         CursorSelect (mouseWindPtr, mouseWindPart, NIL);    /* set cursor to match    */
  86.         
  87.         SystemTask();                            /* let system have some time        */
  88.         
  89.         if (GetNextEvent(everyEvent, &myEvent) != nullEvent)    /* if not nullEvent    */
  90.             {
  91.             switch (myEvent.what)
  92.                 {
  93.                 case (activateEvt):                /* activate or deactivate            */
  94.                     WorkRetCode = 
  95.                             WhichWindow((WindowPtr) myEvent.message, &windSub);
  96.                     if (WorkRetCode == 0)
  97.                         switch (windTbl[windSub].windRec.refCon)
  98.                             {
  99.                             case (ProcMain):
  100.                                 WorkRetCode = MainWindowProc();
  101.                             break;
  102.                             case (ProcText):
  103.                                 WorkRetCode = TextWindowProc();
  104.                             break;
  105.                             case (ProcHelp):
  106.                                 WorkRetCode = HelpWindowProc();
  107.                             break;
  108.                             }
  109.                 break;
  110.  
  111.                 case (mouseDown):
  112.                     WorkRetCode = MouseDownProc();
  113.                 break;
  114.                 
  115.                 case (mouseUp):
  116.                 break;
  117.                 
  118.                 case (diskEvt):
  119.                     if (HiWord(myEvent.message) != noErr)    /* if MountVol had err    */
  120.                         {                                    /* then initialize disk    */
  121.                         SysBeep(NIL);                                /* beep            */
  122.                         SetPt (&workPoint,30,40);                    /* position        */
  123.                         DIBadMount (workPoint, myEvent.message);    /* initialize    */
  124.                         }
  125.                 break;
  126.                 
  127.                 case (networkEvt):
  128.                 break;
  129.                 
  130.                 case (driverEvt):
  131.                 break;
  132.                 
  133.                 case (app1Evt):
  134.                 break;
  135.                 
  136.                 case (app2Evt):
  137.                 break;
  138.                 
  139.                 case (app3Evt):
  140.                 break;
  141.                 
  142.                 case (app4Evt):
  143.                 break;
  144.                 
  145.                 case (keyUp):
  146.                 break;
  147.                 
  148.                 case (keyDown):
  149.                 case (autoKey):
  150.                     WorkRetCode = KeyDownProc();
  151.                 break;
  152.                 
  153.                 case (updateEvt):
  154.                     WorkRetCode = 
  155.                             WhichWindow((WindowPtr) myEvent.message, &windSub);
  156.                     if (WorkRetCode == 0)
  157.                         {
  158.                         BeginUpdate(windTbl[windSub].windPtr);
  159.  
  160.                         switch (windTbl[windSub].windRec.refCon)
  161.                             {
  162.                             case (ProcMain):
  163.                                 WorkRetCode = MainDrawProc();
  164.                             break;
  165.                             case (ProcText):
  166.                                 WorkRetCode = TextDrawProc();
  167.                             break;
  168.                             case (ProcHelp):
  169.                                 WorkRetCode = HelpDrawProc();
  170.                             break;
  171.                             }
  172.                             
  173.                         EndUpdate(windTbl[windSub].windPtr);
  174.                         }
  175.                 break;
  176.                 }
  177.             }
  178.         else
  179.             {
  180.                                         /************************************/
  181.                                         /* null event                        */
  182.                                         /* The system doesn't need our        */
  183.                                         /* attention, so give one loop to    */
  184.                                         /* the proc associated with the        */
  185.                                         /* front window.                    */
  186.                                         /************************************/
  187.             workWindowPtr = FrontWindow();    /* which is front (active) ?    */
  188.             WorkRetCode = 
  189.                     WhichWindow(workWindowPtr, &k);    /* match ptr to table    */
  190.             if (WorkRetCode == 0)                    /* if it's a good match    */
  191.                 {                                    /* then                    */
  192.                 windSub = k;                        /*   set the subscrpt    */
  193.                 switch (windTbl[windSub].windRec.refCon)    /* window type    */
  194.                     {
  195.                     case (ProcMain):
  196.                         WorkRetCode = MainWindowProc();
  197.                     break;
  198.                     case (ProcText):
  199.                         WorkRetCode = TextWindowProc();
  200.                     break;
  201.                     case (ProcHelp):
  202.                         WorkRetCode = HelpWindowProc();
  203.                     break;
  204.                     }
  205.                 }
  206.             }
  207.         }
  208.     /**************************                                                     */
  209.     /* End of Main Event Loop *                                                        */
  210.     /**************************                                                     */
  211.  
  212.     WorkRetCode = MainCloseProc();                    /* close main window            */
  213.         
  214.     WorkRetCode = ShutMac();                        /* Shutdown routines            */
  215.  
  216.     return MainRetCode;                                /*        ALL DONE !!!            */
  217. }
  218. /************************************************************************************/
  219. /*    InitMac                                                                            */
  220. /*  This function initializes the managers which will be used by this program.        */
  221. /************************************************************************************/
  222. int InitMac(void)
  223. {
  224.     int        InitRetCode = 0;                    /* set the return code to good        */
  225.     
  226.                                                                                        
  227.     MaxApplZone();                                /* expand heap to max size            */
  228.     for (j=0; j<20; j++)                        /* get a bunch o' master pointers    */
  229.         MoreMasters();
  230.  
  231.     /************************************                                            */    
  232.     /* NOTE - don't change the order    *                                            */
  233.     /*  of these initialization routines*                                            */
  234.     /************************************                                            */                                                                                           
  235.     InitGraf(&thePort);                         /* intiialize QuickDraw             */
  236.     InitFonts();                                /* initialize Font Manager            */
  237.     InitWindows();                                /* initialize Window Manager        */
  238.     FlushEvents(everyEvent,0);                    /* initialize Event Manager            */
  239.     InitMenus();                                /* initialize Menu Manager            */
  240.     TEInit();                                    /* initialize TextEdit                */
  241.     InitDialogs(NIL);                            /* initialize Dialog Manager        */
  242.     PrOpen();                                    /* initialize Print Manager            */
  243.     InitCursor();                                /* initialize Cursor to arrow        */
  244.     
  245.     DILoad();                                    /* load the Disk Init package        */
  246.     
  247.                                                 /* Get resource file number    after    */
  248.     initResRefNum = CurResFile();                /* these loads and initializations    */
  249.     
  250.     return InitRetCode;
  251. }
  252.  
  253. /************************************************************************************/
  254. /*    ShutMac                                                                            */
  255. /*  This function does routines prior to program shutdown.                            */
  256. /************************************************************************************/
  257.  
  258. int ShutMac(void)
  259. {
  260.     int        SMRetCode = 0;                        /* set the return code to good        */
  261.     
  262.     PrClose();                                    /* close memory of Print Mgr        */
  263.     DIUnload();                                    /* delete disk init package            */    
  264.     DisposeRgn(workRegionH);                    /* release region for TE redraw        */
  265.  
  266.     return SMRetCode;
  267. }
  268.